package ${package.ServiceImpl}

import com.github.pagehelper.PageHelper
import com.github.pagehelper.PageInfo
import com.lgl.common.Pager
import com.lgl.common.service.BaseServiceImpl
import com.lgl.enums.status.StatusEnum
import ${package.Entity}.${entity}
import ${package.Mapper}.${table.mapperName}
import ${package.Service}.${table.serviceName}
import org.slf4j.LoggerFactory
import org.springframework.stereotype.Service
import org.springframework.transaction.annotation.Transactional
import java.io.Serializable
import javax.annotation.Resource

/**
 * <p>
 * ${table.comment!} 服务实现类
 * </p>
 *
 * @author ${author}
 */
@Service
<#if kotlin>
open class ${table.serviceImplName} : BaseServiceImpl<${entity}>(), ${table.serviceName} {
<#else>
public class ${table.serviceImplName} extends BaseServiceImpl<${entity}> implements ${table.serviceName} {
</#if>

    @Resource
    private lateinit var ${serviceNameSimple}Mapper: ${table.mapperName}

    override fun detail(idx: Serializable): ${entity}? {
        val value = selectByPrimaryKey(idx)
        return fill(value)
    }

    @Transactional(rollbackFor = [Exception::class])
    override fun save(value: ${entity}): Int {
        return if (value.idx == null) {
            super.save(value)
        } else {
            update(value)
        }
    }

    override fun getList(pager: Pager<${entity}>, value: ${entity}): Pager<${entity}> {
        if (pager.usePager) {
            PageHelper.offsetPage<Any>(pager.offset, pager.limit)
        }
        val values = getList(value)
        val pageInfo = PageInfo<${entity}>(values)
        pager.rows = pageInfo.list
        pager.total = pageInfo.total
        return pager
    }

    override fun getList(value: ${entity}): List<${entity}> {
        val values = ${serviceNameSimple}Mapper.getList(value)
        values.forEach { fill(it) }
        return values
    }

    override fun delete(idx: Long) {
        ${serviceNameSimple}Mapper.del(idx, StatusEnum.DELETE)
    }

    override fun fill(value: ${entity}?): ${entity}? {
        if (value == null) {
            return null
        }

        return value
    }

    companion object {
        private val logger = LoggerFactory.getLogger(${table.serviceImplName}::class.java)
    }

}
